package tech.heiming.fogedge.po.others;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.mongodb.core.mapping.Document;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @author team members
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Document(collection = "device_message")
public class DeviceMessage implements Serializable {
    /**
     * MQTT主题
     */
    private String topic;

    /**
     * 设备id
     */
    private Integer deviceId;

    /**
     * 数据通道id
     */
    private Integer channelId;

    /**
     * 上传数据的时间
     */
    private LocalDateTime date;

    /**
     * 设备通过数据通道上传的数据
     */
    private List<Map<String, Object>> data;

    public Map<String, Object> getDataMap() {
        return data.stream()
                .flatMap(map -> map.entrySet().stream())
                .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
    }
}
